using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Home_PlacementCategories : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAddNewCategory_Click(object sender, EventArgs e)
    {
        if (this.txtNewCategoryName.Text.Length > 0)
        {
            this.lblNewCategoryMessage.Text = string.Empty;

            PlacementManager.CategoryComponent oCategoryC = new PlacementManager.CategoryComponent();
            PlacementManager.Category oNewCategory = new PlacementManager.Category();
            oNewCategory.CategoryName = this.txtNewCategoryName.Text.Trim();
            oNewCategory.CreatedBy = User.Identity.Name;
            oNewCategory.DateCreated = DateTime.Now;
            oNewCategory.DateUpdated = DateTime.Now;
            oNewCategory.DivisionId = Int32.Parse(Session["DivisionId"].ToString());
            oNewCategory.IsActive = true;
            oNewCategory.UpdatedBy = User.Identity.Name;
            oCategoryC.Insert(oNewCategory);

            this.gvCategories.DataBind();
            this.txtNewCategoryName.Text = string.Empty;
        }
        else
        {
            this.lblNewCategoryMessage.Text = "Please enter a new category name.";
        }

    }
    protected void gvCategories_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        PlacementManager.CategoryComponent oCategoryC = new PlacementManager.CategoryComponent();
        PlacementManager.Category oCategory = oCategoryC.SelectOne(Int32.Parse(this.gvCategories.DataKeys[e.RowIndex].Value.ToString()));

        e.NewValues.Add("CategoryId", oCategory.CategoryId);
        e.NewValues.Add("CreatedBy", oCategory.CreatedBy);
        e.NewValues.Add("DateCreated", oCategory.DateCreated);
        e.NewValues.Add("DivisionId", oCategory.DivisionId);
        e.NewValues.Add("DateUpdated", DateTime.Now);
        e.NewValues.Add("UpdatedBy", User.Identity.Name);


    }
}
